package mhserver;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;

import java.util.List;

import mh.message.IncomingMessage;
import mh.message.MessageParser;

/**
 * Decoder that creates an <code>IncomingMessage</code> from a <code>String</code> in the inbound buffer.
 * 
 * @author Gianmarco Laggia
 * 
 */
public class MessageDecoder extends MessageToMessageDecoder<String> {

	@Override
	protected void decode(ChannelHandlerContext ctx, String in, List<Object> out) throws Exception {
		IncomingMessage incomingMsg = MessageParser.parseMessage(in);
		out.add(incomingMsg);
	}
}
